import yargs from 'yargs';
import PageComponent from './PageComponent';
import ServiceComponent from './ServiceComponent';
import WidgetComponent from './WidgetComponent';


class Generator {
    constructor() {
        this.argv = yargs
            .alias('a', 'action')
            .alias('n', 'name')
            .option('migrate', {
                alias: 'm',
                describe: 'migrate all component'
            })
            .option('type', {
                alias: 't',
                describe: 'choose a type of component s(service) w(widget) p(page)',
                choices: ['s', 'w', 'p'],
            })
            .option('create', {
                alias: 'c',
                describe: 'create a component',
            })
            .option('remove', {
                alias: 'r',
                describe: 'remove a component',
            })
            .option('update', {
                alias: 'u',
                describe: 'update a component',
            })
            .option('init', {
                alias: 'i',
                describe: 'init a project',
            })
            .argv;
    }

    generateTask() {
        //console.log(this.argv);
        if ((this.argv.create || this.argv.remove || this.argv.update) && this.argv.type) {

            this.switchToComponentOperation(this.argv.type);

        }
    }

    //projects call method of each type of project 
    projectOperation() {

    }



    //components
    switchToComponentOperation(type) {
        return {
            s: () => this.serviceComponentOperation(),
            w: () => this.widgetComponentOperation(),
            p: () => this.pageComponentOperation(),
        }[type]();
    }

    pageComponentOperation() {
        let c = new PageComponent();
        if (this.argv.create) {
            c.create({ componentName: this.argv.create });
        } else if (this.argv.remove) {
            c.remove({ componentName: this.argv.remove });
        }

    }

    widgetComponentOperation() {
        let c = new WidgetComponent();
        if (this.argv.create) {
            c.create({ componentName: this.argv.create });
        } else if (this.argv.remove) {
            c.remove({ componentName: this.argv.remove });
        }

    }

    serviceComponentOperation() {
        let c = new ServiceComponent();
        if (this.argv.create) {
            c.create({ componentName: this.argv.create });
        } else if (this.argv.remove) {
            c.remove({ componentName: this.argv.remove });
        }
    }













}

export default Generator;